import { OrderwholeListData, OrderListData } from '/@/api/tb/tbOrder'

export const GetWhole= async()=>{
  const res= await OrderwholeListData()
  const newarr = res.list.map(item => {
    return {
      value: item.id,
      label: item.name,
      pid: item.pid
    }
  })
  let formatObj = newarr.reduce((pre, cur) => {
  return {...pre, [cur['value']]: cur}
}, {});

let formatArray = newarr.reduce((arr, cur) => {
  let pid = cur.pid ? cur.pid : 0;
  let parent = formatObj[pid];
  if (parent) {
    parent.children ? parent.children.push(cur) : parent.children=[cur];
  } else {
    arr.push(cur)
  }
  return arr;
}, []);
return formatArray;
}